package com.zhejiangzhengyuan.municipal_pumping_station.controller;
import com.zhejiangzhengyuan.municipal_common.entity.Device;
import com.zhejiangzhengyuan.municipal_common.response.ResponseVo;
import com.zhejiangzhengyuan.municipal_common.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :linju
 * @create on : 2019/12/10
 */
@RestController
@Slf4j
@RequestMapping("/station/pumpStationDeviceManagement")
@Api(tags = "泵站设备管理")
public class DeviceManagementController {

    private  final String pumpDeviceType="泵站设备";
    private  final String stormSewageDeviceType="雨污水处理设备";
    @Autowired private DeviceService deviceService;

    @ApiOperation("查询泵站设备")
    @GetMapping("/selectPumpDevice")
    public ResponseVo selectPumpDevice(Integer pageNo,Integer pageSize) {
        return deviceService.selectPumpDevice(pageNo,pageSize,pumpDeviceType);
    }

    @ApiOperation("添加泵站设备")
    @PostMapping("/savePumpDevice")
    public ResponseVo savePumpDevice(@RequestBody Device device) {
        device.setType(pumpDeviceType);
        device.setName(pumpDeviceType);
        //泵站页面未提供物探点号
        device.setGeophysicalPeriod("物探点号");
        device.setBatteryLife("十年");
        return deviceService.saveDevice(device);
    }

    @ApiOperation("更新泵站设备")
    @PostMapping("/updatePumpDevice")
    public ResponseVo updatePumpDevice(@RequestBody Device device){
        int i = deviceService.updateDevice(device);
        return i>0?ResponseVo.SUCCESS:ResponseVo.SERVER_ERROR;
    }

    @ApiOperation("根据ID删除泵站设备")
    @DeleteMapping("/removePumpDeviceById")
    public ResponseVo removePumpDeviceById(Integer id) {
        return deviceService.removeById(id) ? ResponseVo.SUCCESS : ResponseVo.SERVER_ERROR;
    }

    @ApiOperation("查询雨污水处理终端设备")
    @GetMapping("/selectStormSewageDevice")
    public ResponseVo selectStormSewageDevice(Integer pageNo,Integer pageSize) {
        return deviceService.selectPumpDevice(pageNo,pageSize,stormSewageDeviceType);
    }

    @ApiOperation("添加雨污水处理终端设备")
    @PostMapping("/saveStormSewageDevice")
    public ResponseVo saveStormSewageDevice(@RequestBody Device device) {
        device.setType(stormSewageDeviceType);
        device.setName(stormSewageDeviceType);
        device.setGeophysicalPeriod("物探点号");
        device.setBatteryLife("十年");
        return deviceService.saveDevice(device);
    }

    @ApiOperation("更新雨污水处理终端设备")
    @PostMapping("/updateStormSewageDevice")
    public ResponseVo updateStormSewageDevice(@RequestBody Device device){
        int i = deviceService.updateDevice(device);
        return i>0?ResponseVo.SUCCESS:ResponseVo.SERVER_ERROR;
    }

    @ApiOperation("根据ID雨污水处理终端设备")
    @DeleteMapping("/removeStormSewageDeviceById")
    public ResponseVo removeStormSewageDeviceById(Integer id) {
        return deviceService.removeById(id) ? ResponseVo.SUCCESS : ResponseVo.SERVER_ERROR;
    }
}
